package net.xiduth.game.npc.quest;

import net.xiduth.game.Animation;
import net.xiduth.game.Entity;
import net.xiduth.game.WorldTile;
import net.xiduth.game.npc.NPC;
import net.xiduth.game.npc.combat.NPCCombatDefinitions;
import net.xiduth.game.tasks.WorldTask;
import net.xiduth.game.tasks.WorldTasksManager;

@SuppressWarnings("serial")
public class RFDNpc extends NPC {

	public RFDNpc(int id, WorldTile tile) {
		super(id, tile, -1, true, true);
	}
	
	@Override
	public void sendDeath(Entity source) {
		if (this.getMostDamageReceivedSourcePlayer() != null) {
		//	this.getMostDamageReceivedSourcePlayer().setLastRFDWave(this.getMostDamageReceivedSourcePlayer().getLastRFDWave() + 1);
		}
		getAttributes().put("died", true);
		final NPCCombatDefinitions defs = getCombatDefinitions();
		resetWalkSteps();
		getCombat().removeTarget();
		setNextAnimation(null);
		WorldTasksManager.schedule(new WorldTask() {
			int loop;

			@Override
			public void run() {
				if (loop == 0) {
					setNextAnimation(new Animation(defs.getDeathEmote()));
				} else if (loop >= defs.getDeathDelay()) {
					drop();
					reset();
					setLocation(getRespawnTile());
					finish();
					if (!isSpawned())
						setRespawnTask();
					stop();
				}
				loop++;
			}
		}, 0, 1);
	}

}
